<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var book = {
            name:'javascript设计模式',
            price:'55',
        }
        var book1 = {
            name:'你不知道的javascript',
            price:'44',
        }
        var anotherbook = {
            color:'white',
            type:['css','html','javascript']
        }
        var otherbook = {
            date: new Date()
        }
        var lastbook = {
           '出版社': 'beijing'
        }
        //单继承
        var oneextend = function (target,source) {
            //遍历源对象中的属性
            for (var prototy in source){
                target[prototy] = source[prototy]
            }
            return target
        }
        oneextend(book,anotherbook)
        console.log('book---',book)
        //缺点,引用类型的地址共享，存在浅复制
        //book.color = 'blue'
        //book.type.push('web')
        console.log('anotherbook---',anotherbook)
        //多继承
        var moreextend = function (target,...args) {
            //利用es6展开符
            arr = [...args]
            for (let i = 0 ;i< arr.length;i++){
                //获取每个对象
                oneextend(target,arr[i])
                //对每个对象进行复制
            }
            return target
        }
        moreextend(book1,anotherbook,otherbook,lastbook)
        console.log(book1)

        //多态
        //一个方法多种调用方式
        function add (params) {
            var args = arguments
            var len = args.length
            switch(len){
                case 0: return undefined
                case 1: return args[0]
                case 2: return args[0]+args[1]
                
            }
        }
        function add1(...args) {
            sum = [...args].reduce((a, b) => {
                return a + b;
            });

            return sum
        }
        console.log(add(10,2))
        console.log(add1(1,2,3,4,5,6,7))

    </script>
</body>
</html>